package com.example.myframe.adapter

import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.example.myframe.callback.DataBindingConsumer

/**
 * 用于Rv的DataBinding快速开发适配器
 * kotlin用BRV更方便
 * */
abstract class BaseDataBindingAdapter<T, BD : ViewDataBinding>(
    @LayoutRes layId: Int,
    private val brId: Int,
    list: MutableList<T>
) :
    LoadMoreModule, BaseQuickAdapter<T, BaseDataBindingHolder<BD>>(layId, list) {
    var convert: DataBindingConsumer<BD, T>? = null

    override fun convert(holder: BaseDataBindingHolder<BD>, item: T) {
        val dataBinding = holder.dataBinding ?: return
        dataBinding.setVariable(brId, item)
        convert?.convert(holder, item)
        dataBinding.executePendingBindings()
    }

}
